//
//  AgencyDetailsViewController.m
//  Edumap
//
//  Created by 辰领科技 on 16/7/21.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "AgencyDetailsViewController.h"
#import "AgencyDetailsTableViewCell.h"
#import "AgencyDetailsCollectionViewCell.h"
#import "CourseDetailsViewController.h"
#import "AgencyVideoShowViewController.h"
#import "SharePopView.h"

static NSString *cellIdentifier = @"AgencyDetailsTableViewCell";
static NSString *collectionIdentifier = @"AgencyDetailsCollectionViewCell";
#import "UMSocial.h"
#import "UMSocialWechatHandler.h"
#import "UMSocialQQHandler.h"
@interface AgencyDetailsViewController ()
<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource,BestScrollViewDelegate,BestScrollViewDatasource,MWPhotoBrowserDelegate>

@property (strong, nonatomic) IBOutlet UIScrollView *scroview;
@property (strong, nonatomic) IBOutlet UIButton *collectionButton;
@property (strong, nonatomic) IBOutlet UIImageView *headerImage;//头像
@property (strong, nonatomic) IBOutlet UILabel *companyNAmeLabel;//公司名字
@property (strong, nonatomic) IBOutlet UILabel *IntroductionLabel;//机构简介
@property (strong, nonatomic) IBOutlet UIButton *unfoldButton;

@property (strong, nonatomic) IBOutlet UIView *BusinessInformationView;//商家信息View
@property (strong, nonatomic) IBOutlet UILabel *timeLabel;//时间
@property (strong, nonatomic) IBOutlet UILabel *nameLabel;//名字
@property (strong, nonatomic) IBOutlet UILabel *phoneNumberLabel;//电话
@property (strong, nonatomic) IBOutlet UILabel *QQlabel;//QQ
@property (strong, nonatomic) IBOutlet UILabel *urlLabel;//网址
@property (strong, nonatomic) IBOutlet UILabel *addressLabel;//地址

@property (strong, nonatomic) IBOutlet UIView *AgencyShowView;//机构展示View
@property (strong, nonatomic) IBOutlet UICollectionView *collectionView;

@property (strong, nonatomic) IBOutlet UIView *CourseListView;//课程列表View
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSArray *tableViewArray;

@property (strong, nonatomic) IBOutlet UIButton *BGbutton;
@property (strong, nonatomic) IBOutlet UIView *callView;
@property (strong, nonatomic) IBOutlet UILabel *phoneNumber;
@property (strong, nonatomic) IBOutlet UIButton *cancelButton;
@property (strong, nonatomic) IBOutlet UIButton *callButton;
@property (strong, nonatomic) IBOutlet UILabel *collectionLabel;


@property (strong, nonatomic) IBOutlet UIView *collectionview;
@property (strong, nonatomic) IBOutlet UIButton *returnButton;

@property (strong, nonatomic) NSDictionary *AgencyDetailsDic;

@property(nonatomic,strong)NSArray * showArray;

@property (nonatomic,strong)  BestScrollView *headerScroll;//滚动栏
@property (nonatomic,strong)  NSMutableArray  *imageArray;

@property (nonatomic,strong) NSString *mstoContent;

@property(nonatomic,strong)NSMutableArray * photos;
@property(nonatomic,strong)MWPhotoBrowser * browser;
@end

@implementation AgencyDetailsViewController

- (void)viewDidDisappear:(BOOL)animated{
    _backBlock();
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    //状态栏文字颜色
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
    _photos = [NSMutableArray array];
    [self institutionsDetails];
    [self AgencyShow];
    [self course];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _showArray = [NSArray array];
    _imageArray =[NSMutableArray array];
    [self initViewLayout];
}

- (void)initViewLayout {
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.callView];
    [self adaptiveViewLayout:self.collectionView];
    [self adaptiveViewLayout:self.scroview];
    [self adaptiveViewLayout:self.BusinessInformationView];
    [self adaptiveViewLayout:self.AgencyShowView];
    [self adaptiveViewLayout:self.CourseListView];
    _scroview.contentSize = flexibleSize(CGSizeMake(0, _CourseListView.frame.origin.y+_CourseListView.frame.size.height), NO);
    //广告栏
    _headerScroll=[[BestScrollView alloc]  initWithFrame:flexibleFrame(CGRectMake(0, 0, 320, 177), NO)];
    [self.scroview insertSubview:_headerScroll belowSubview:_collectionButton];

    
    [self.tableView registerNib:[UINib nibWithNibName:cellIdentifier bundle:nil] forCellReuseIdentifier:cellIdentifier];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    UICollectionViewFlowLayout *flowLayout =[[UICollectionViewFlowLayout alloc]init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumInteritemSpacing = 10;
    flowLayout.minimumLineSpacing = 10;
    self.collectionView.collectionViewLayout = flowLayout;
    

    [self.collectionView registerNib:[UINib nibWithNibName:collectionIdentifier bundle:nil] forCellWithReuseIdentifier:collectionIdentifier];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.backgroundColor = [UIColor whiteColor];
    
    _headerImage.layer.masksToBounds = YES;
    _headerImage.layer.cornerRadius = 25*VerticalRatio();
    self.callView.layer.cornerRadius = 5*VerticalRatio();
    self.cancelButton.layer.cornerRadius = 5*VerticalRatio();
    self.callButton.layer.cornerRadius = 5*VerticalRatio();
    self.collectionView.layer.cornerRadius = 5*VerticalRatio();
    self.returnButton.layer.cornerRadius = 5*VerticalRatio();
    
    _browser = [[MWPhotoBrowser alloc] init];
    
    // Set options
    _browser.displayActionButton = YES; // Show action button to allow sharing, copying, etc (defaults to YES)
    _browser.displayNavArrows = NO; // Whether to display left and right nav arrows on toolbar (defaults to NO)
    _browser.displaySelectionButtons = NO; // Whether selection buttons are shown on each image (defaults to NO)
    _browser.zoomPhotosToFill = YES; // Images that almost fill the screen will be initially zoomed to fill (defaults to YES)
    _browser.alwaysShowControls = NO; // Allows to control whether the bars and controls are always visible or whether they fade away to show the photo full (defaults to NO)
    _browser.enableGrid = YES; // Whether to allow the viewing of all the photo thumbnails on a grid (defaults to YES)
    _browser.startOnGrid = NO; // Whether to start on the grid of thumbnails instead of the first photo (defaults to NO)
    
    // Optionally set the current visible photo before displaying
    // Manipulate
    [_browser showNextPhotoAnimated:YES];
    [_browser showPreviousPhotoAnimated:YES];
}
#pragma mark - 查询机构详情
- (void)institutionsDetails {
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    if ([Common getLoginStatus]) {
        [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
    }
    [dic setObject:self.mstoId forKey:@"mstoId"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:JY_mallStoreDetails withHttpType:@"POST" withTag:JY_JY_mallStoreDetails];
}

#pragma mark - 查询机构展示
- (void)AgencyShow {
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:self.mstoId forKey:@"mallStoreId"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:JY_mallStoreExtendsList withHttpType:@"POST" withTag:JY_JY_mallStoreExtendsList];
}

#pragma mark - 获取课程
-(void)course{
    
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:self.mstoId forKey:@"mgooStoreId"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:JY_mallGoodsList withHttpType:@"POST" withTag:JY_JY_mallGoodsList];
}

- (IBAction)back:(id)sender {
    [self backBtn];
    _headerScroll.datasource = nil;
    _headerScroll.delegate = nil;
}

#pragma mark - 展开
- (IBAction)develop:(UIButton *)sender {
    if (!_unfoldButton.selected) {
        _IntroductionLabel.numberOfLines = 0;
        _IntroductionLabel.text = [NSString stringWithFormat:@"%@",self.AgencyDetailsDic[@"mstoContent"]];
        [_IntroductionLabel sizeToFit];
        _unfoldButton.frame = CGRectMake(_unfoldButton.frame.origin.x, _IntroductionLabel.frame.origin.y+_IntroductionLabel.frame.size.height+5, _unfoldButton.frame.size.width, _unfoldButton.frame.size.height);
        
        _BusinessInformationView.frame = CGRectMake(_BusinessInformationView.frame.origin.x, _unfoldButton.frame.origin.y+_unfoldButton.frame.size.height+10, _BusinessInformationView.frame.size.width, _BusinessInformationView.frame.size.height);
        
        _AgencyShowView.frame = CGRectMake(_AgencyShowView.frame.origin.x, _BusinessInformationView.frame.origin.y+_BusinessInformationView.frame.size.height, _AgencyShowView.frame.size.width, _AgencyShowView.frame.size.height);
        
        _CourseListView.frame = CGRectMake(_CourseListView.frame.origin.x, _AgencyShowView.frame.origin.y+_AgencyShowView.frame.size.height, _CourseListView.frame.size.width, _CourseListView.frame.size.height);
        
    } else if (_unfoldButton.selected) {
       
        _IntroductionLabel.frame = flexibleFrame(CGRectMake(24, 291, 283, 54), NO);
        _IntroductionLabel.numberOfLines = 3;
         self.IntroductionLabel.text = [NSString stringWithFormat:@"%@…",_mstoContent];
        _unfoldButton.frame = flexibleFrame(CGRectMake(138, 343, _unfoldButton.frame.size.width/VerticalRatio(), _unfoldButton.frame.size.height/VerticalRatio()), NO);
        
        _BusinessInformationView.frame = flexibleFrame(CGRectMake(0, 366, _BusinessInformationView.frame.size.width, _BusinessInformationView.frame.size.height), NO);
        
        _AgencyShowView.frame = flexibleFrame(CGRectMake(0, 586, _AgencyShowView.frame.size.width/VerticalRatio(), _AgencyShowView.frame.size.height/VerticalRatio()), NO);
        
        _CourseListView.frame = flexibleFrame(CGRectMake(0, 719, _CourseListView.frame.size.width/VerticalRatio(), _CourseListView.frame.size.height/VerticalRatio()), NO);
        
    }
    _scroview.contentSize = CGSizeMake(0, _CourseListView.frame.origin.y+_CourseListView.frame.size.height);
    sender.selected = !sender.selected;
}

#pragma mark - 微信 && 朋友圈 && QQ空间 && QQ好友
- (IBAction)shareto:(UIButton *)sender {
    if (sender.tag == 100) {
        //微信好友
        [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatSession] content:_companyNAmeLabel.text image:[UIImage imageNamed:@"58.png"] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
            if (response.responseCode == UMSResponseCodeSuccess) {
                //            NSLog(@"分享成功！");
            }
        }];
        
    } else if (sender.tag == 101) {
        //朋友圈
        [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatTimeline] content:_companyNAmeLabel.text image:[UIImage imageNamed:@"58.png"] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
            if (response.responseCode == UMSResponseCodeSuccess) {
                //            NSLog(@"分享成功！");
            }
        }];
        
        
    } else if (sender.tag == 102) {
        //QQ空间
        [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToQzone] content:_companyNAmeLabel.text image:[UIImage imageNamed:@"58.png"] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
            if (response.responseCode == UMSResponseCodeSuccess) {
                //            NSLog(@"分享成功！");
            }
        }];
        
    } else if (sender.tag == 103) {
        //QQ好友
        [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToQQ] content:_companyNAmeLabel.text image:[UIImage imageNamed:@"58.png"] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
            if (response.responseCode == UMSResponseCodeSuccess) {
                //            NSLog(@"分享成功！");
            }
        }];
    }
}

#pragma mark - 分享
- (IBAction)share:(id)sender {

    SharePopView * popView = [[SharePopView alloc]initWithTitles:@[@"微信好友",@"朋友圈",@"QQ空间",@"QQ好友"] complect:^(NSInteger index) {
        if (index == 0) {
            //微信好友
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatSession] content:_companyNAmeLabel.text image:[UIImage imageNamed:@"58.png"] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
                if (response.responseCode == UMSResponseCodeSuccess) {
                    //            NSLog(@"分享成功！");
                }
            }];
            
        } else if (index == 1) {
            //朋友圈
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatTimeline] content:_companyNAmeLabel.text image:[UIImage imageNamed:@"58.png"] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
                if (response.responseCode == UMSResponseCodeSuccess) {
                    //            NSLog(@"分享成功！");
                }
            }];
            
            
        } else if (index == 2) {
            //QQ空间
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToQzone] content:_companyNAmeLabel.text image:[UIImage imageNamed:@"58.png"] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
                if (response.responseCode == UMSResponseCodeSuccess) {
                    //            NSLog(@"分享成功！");
                }
            }];
            
        } else if (index == 3) {
            //QQ好友
            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToQQ] content:_companyNAmeLabel.text image:[UIImage imageNamed:@"58.png"] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
                if (response.responseCode == UMSResponseCodeSuccess) {
                    //            NSLog(@"分享成功！");
                }
            }];
        }

    }];
    [popView show];
}

#pragma mark - 收藏
- (IBAction)collection:(id)sender {
    if (![Common getLoginStatus]) {
        [[AppDelegate sharedAppDelegate]ShowLoginPage];
        return;
    }
    if (self.collectionButton.selected) {
        NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
        [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
        [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"msadMemberId"];
        [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
        [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
        [dic setObject:self.mstoId forKey:@"mstoId"];
        self.shareApi.delegate=self;
        [self.shareApi  requestOperationWithDic:dic withPath:JY_canleMallCollectStore withHttpType:@"POST" withTag:JY_JY_canleMallCollectStore];
    } else if (!self.collectionButton.selected) {
        NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
        [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
        [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"msadMemberId"];
        [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
        [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
        [dic setObject:self.mstoId forKey:@"mstoId"];
        self.shareApi.delegate=self;
        [self.shareApi  requestOperationWithDic:dic withPath:JY_mallCollectStore withHttpType:@"POST" withTag:JY_JY_mallCollectStore];
    }
}

#pragma mark - 打电话
- (IBAction)call:(id)sender {
    _BGbutton.hidden = NO;
    _callView.hidden = NO;
}

#pragma mark - 拨号
- (IBAction)phoneCall:(id)sender {
    [Common callPhone:_phoneNumberLabel.text view:self.view];
}

#pragma mark - 取消拨号&&取消分享&&取消收藏
- (IBAction)cancel:(id)sender {
    _BGbutton.hidden = YES;
    _callView.hidden = YES;
    _collectionview.hidden = YES;
}


#pragma mark -- UICollectionViewDataSource
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _showArray.count;
}
//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(100*VerticalRatio(), 85*VerticalRatio());
    
}
//定义每个UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0, 0, 0, 0);
    
}
//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    AgencyDetailsCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:collectionIdentifier forIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor whiteColor];
    NSDictionary * dic= _showArray[indexPath.row];
    NSString * image = [NSString stringWithFormat:@"%@",dic[@"msexUrl"]];
    if (image.length>0) {
        [cell.image sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,image]]];
    }
    
    cell.videoImage.hidden = YES;
    NSString * type = [NSString stringWithFormat:@"%@",dic[@"msexType"]];
    if ([type isEqualToString:@"2"]) {
        cell.videoImage.hidden = NO;
    }
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary * dic= _showArray[indexPath.row];
    NSString * type = [NSString stringWithFormat:@"%@",dic[@"msexType"]];
    if ([type isEqualToString:@"2"]) {
        UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"TeachStoryboard" bundle:nil];
        AgencyVideoShowViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"AgencyVideoShow"];
        page.videoId = [NSString stringWithFormat:@"%@",dic[@"msexId"]];
        [[Common getNavigation] pushViewController:page];
    }
    if ([type isEqualToString:@"1"]) {
        _browser.titleStr = @"机构展示";
        _browser.delegate = self;
        [_browser setCurrentPhotoIndex:0];
        // Present
        UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:_browser];
        [self presentViewController:nc animated:YES completion:nil];
    }
}

- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    return self.photos.count;
}

- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    if (index < self.photos.count) {
        return [self.photos objectAtIndex:index];
    }
    return nil;
}

- (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index{
    NSString * str = [NSString stringWithFormat:@"%ld/%ld",index+1,_photos.count];
    return str;
}



#pragma mark - <UITableViewDelegate&&UITableViewDataSource>
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

//定义 UITableView cell 的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.tableViewArray.count;
}

//定义 UITableView cell 的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 95*VerticalRatio();
}

//定义 UITableView cell 展示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    AgencyDetailsTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell= [[AgencyDetailsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        
    }
    for (UIView *view in cell.subviews) {
        if ([view isKindOfClass:[UILabel class]] ||[view isKindOfClass:[UIImageView class]]||[view isKindOfClass:[UIScrollView class]]||[view isKindOfClass:[UIButton class]]) {
            [view removeFromSuperview];
        }
    }
    
    if (![self.tableViewArray[indexPath.row][@"mgooImage"] isEqual:[NSNull null]]) {
        [cell.image sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,self.tableViewArray[indexPath.row][@"mgooImage"]]]];
    }
    cell.titleLabel.text = [NSString stringWithFormat:@"%@",self.tableViewArray[indexPath.row][@"mgooName"]];
    cell.moneyLabel.text = [NSString stringWithFormat:@"￥%@",self.tableViewArray[indexPath.row][@"mgooPrice"]];
    cell.detailLabel.text = [NSString stringWithFormat:@"%@",self.tableViewArray[indexPath.row][@"mgooContext"]];
    return cell;
}

//定义 UITableView cell 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"TeachStoryboard" bundle:nil];
    CourseDetailsViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"CourseDetails"];
    
    page.mgooId = self.tableViewArray[indexPath.row][@"mgooId"];
    page.mstoId = self.tableViewArray[indexPath.row][@"mgooStoreId"];
    page.backBlock = ^(){
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    };
    [[Common getNavigation] pushViewController:page];
}



#pragma  mark BestView Delegate Data=source=====================


- (NSInteger)numberOfPages
{
    
    return  self.imageArray.count;
    
}

- (UIView *)pageAtIndex:(NSInteger)index
{
    
    if (self.imageArray.count>0) {
        
        UIImageView  *imageView=[[UIImageView alloc]  initWithFrame: flexibleFrame(CGRectMake(0, 0, 320, 177), NO)];
        [imageView  sd_setImageWithURL:[NSURL URLWithString: [NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,_imageArray[index]]] placeholderImage:[UIImage imageNamed:@"school5"]];
        return imageView;
    }
    return nil;
}


- (void)didClickPage:(BestScrollView *)csView atIndex:(NSInteger)index
{
}


#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    if (tag==JY_JY_mallStoreDetails) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
        }else {
            self.AgencyDetailsDic = [NSDictionary dictionary];
            self.AgencyDetailsDic = database[@"result"];
            
            NSString * images = [NSString stringWithFormat:@"%@",_AgencyDetailsDic[@"mstoMultiImage"]];
            if (images.length>1) {
                images = [images substringToIndex:images.length-1];
            }
            
            self.imageArray = [[images componentsSeparatedByString:@","]mutableCopy];
            self.headerScroll.delegate=self;
            self.headerScroll.datasource=self;
            [self.headerScroll showImageArray:self.imageArray   withAnimation:YES];

            
            NSString *isCollect = [NSString stringWithFormat:@"%@",self.AgencyDetailsDic[@"isCollect"]];
            if ([isCollect isEqualToString:@"1"]) {
                self.collectionButton.selected = NO;
            } else if ([isCollect isEqualToString:@"2"]) {
                self.collectionButton.selected = YES;
            }
            NSString *imageStr = [NSString stringWithFormat:@"%@",self.AgencyDetailsDic[@"mstoImage"]];
            if (imageStr && imageStr.length>0 && ![self.AgencyDetailsDic[@"mstoImage"] isEqual:[NSNull null]]) {
                [self.headerImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,imageStr]]];
            }
            self.companyNAmeLabel.text = [NSString stringWithFormat:@"%@",self.AgencyDetailsDic[@"mstoName"]];
            
            NSString *mstoContent = [NSString stringWithFormat:@"%@",self.AgencyDetailsDic[@"mstoContent"]];
            if (mstoContent.length <= 65) {
                self.unfoldButton.hidden = YES;
                _IntroductionLabel.numberOfLines = 0;
                self.IntroductionLabel.text = [NSString stringWithFormat:@"%@",self.AgencyDetailsDic[@"mstoContent"]];
                [_IntroductionLabel sizeToFit];
            } else if (mstoContent.length > 65) {
                self.unfoldButton.hidden = NO;
                
                NSString *string;
                for (int i = 64 ; i >= 0; i--) {
                    string =  [mstoContent substringWithRange:NSMakeRange(i,1)];
                
                    NSString *str = @"，。、《》？；：’‘“”、|【】{}！@#￥%……&*（）-+=…";
                    
                    if (![str containsString:string]) {
                        _mstoContent = [mstoContent substringToIndex:i];
                        self.IntroductionLabel.text = [NSString stringWithFormat:@"%@…",_mstoContent];
                        break;
                    }
                }
            }
            
        
            self.timeLabel.text = [NSString stringWithFormat:@"%@-%@",self.AgencyDetailsDic[@"mstoOpenTime"],self.AgencyDetailsDic[@"mstoCloseTime"]];
            self.nameLabel.text = [NSString stringWithFormat:@"%@",self.AgencyDetailsDic[@"mstoName"]];
            self.phoneNumberLabel.text = [NSString stringWithFormat:@"%@",self.AgencyDetailsDic[@"mstoPhone"]];
            self.phoneNumber.text = [NSString stringWithFormat:@"%@",self.AgencyDetailsDic[@"mstoPhone"]];
            self.QQlabel.text = [NSString stringWithFormat:@"%@",self.AgencyDetailsDic[@"mstoQq"]];
            self.urlLabel.text = [NSString stringWithFormat:@"%@",self.AgencyDetailsDic[@"mstoWebsite"]];
            self.addressLabel.text = [NSString stringWithFormat:@"%@",self.AgencyDetailsDic[@"mstoAddress"]];
            
            NSString *mstoMultiImage = [NSString stringWithFormat:@"%@",self.AgencyDetailsDic[@"mstoMultiImage"]];
            NSArray * array = [mstoMultiImage componentsSeparatedByString:@","];
            for (int i = 1; i <= array.count; i++) {
                UIImageView *imageView;
                imageView.frame = flexibleFrame(CGRectMake(6+(i*101), 34, 95, 65), NO);
            NSString *imageStr;
            if (imageStr && imageStr.length>0 && ![array[i-1] isEqual:[NSNull null]]) {
                    [imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,imageStr]]];
                    [self.AgencyShowView addSubview:imageView];
                }

            }
            
            
        } 
        
    } else if (tag==JY_JY_mallCollectStore) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else {
            self.collectionLabel.text = @"收藏成功";
            _collectionview.hidden = NO;
            _BGbutton.hidden = NO;
            self.collectionButton.selected = YES;
        }
        
    } else if (tag==JY_JY_canleMallCollectStore) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else {
            self.collectionLabel.text = @"取消收藏";
            _collectionview.hidden = NO;
            _BGbutton.hidden = NO;
            self.collectionButton.selected = NO;
        }
        
    } else if (tag==JY_JY_mallGoodsList) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else {

            self.tableViewArray = [NSArray array];
            self.tableViewArray = database[@"result"][@"rows"];
            _tableView.frame = CGRectMake(0, CGRectGetMinY(_tableView.frame), CGRectGetWidth(_tableView.frame), 95*_tableViewArray.count*VerticalRatio());
            _CourseListView.frame = CGRectMake(0, CGRectGetMinY(_CourseListView.frame), CGRectGetWidth(_CourseListView.frame), CGRectGetMaxY(_tableView.frame));
            _scroview.contentSize = flexibleSize(CGSizeMake(0, CGRectGetMaxY(_CourseListView.frame)), NO);
            [self.tableView reloadData];
        }
        
    }else if (tag == JY_JY_mallStoreExtendsList){
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else {
            _showArray = database[@"result"];
            for (int i = 0; i < _showArray.count; i++) {
                NSString *msexType = [NSString stringWithFormat:@"%@",_showArray[i][@"msexType"]];
                if ([msexType isEqualToString:@"1"]) {
                     NSString *url = [NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,_showArray[i][@"msexUrl"]];
                    MWPhoto * photo = [[MWPhoto alloc]initWithURL:[NSURL URLWithString:url]];
                    [_photos addObject:photo];
                }
            }
            [_collectionView reloadData];
        }
    }
}
-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    //
    [self dismissWaitDialog];
    
    
}


@end
